package com.hck.infrastructure.persistent.repository;

import com.hck.domain.consultation.model.entity.ConsultationReplyEntity;
import com.hck.domain.consultation.repository.IConsultationReplyRepository;
import com.hck.infrastructure.persistent.dao.IConsultationReplyDao;
import com.hck.infrastructure.persistent.po.ConsultationReply;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * ConsultationReplyRepository class description here.
 *
 * @author 黄朝看
 * @date 2025/6/30
 */
@Repository
public class ConsultationReplyRepository implements IConsultationReplyRepository {
    @Resource
    private IConsultationReplyDao consultationReplyDao;

    @Override
    public void save(ConsultationReplyEntity replyEntity) {
        ConsultationReply consultationReply = new ConsultationReply();
        BeanUtils.copyProperties(replyEntity, consultationReply);
        consultationReplyDao.insert(consultationReply);
        replyEntity.setId(consultationReply.getId());
    }

    @Override
    public List<ConsultationReplyEntity> findByConsultationId(Long consultationId) {
        return consultationReplyDao.selectByConsultationId(consultationId).stream().map(po -> {
            ConsultationReplyEntity entity = new ConsultationReplyEntity();
            BeanUtils.copyProperties(po, entity);
            return entity;
        }).collect(Collectors.toList());
    }
}
